require.config({
    paths: {
        'simple-module':'addons/simditor/js/module',
        'simple-hotkeys':'addons/simditor/js/hotkeys',
        'dompurify':'addons/simditor/js/dompurify',
        'beautify':'addons/simditor/js/beautify',
        'beautify-css':'addons/simditor/js/beautify-css',
        'html_beautify':'addons/simditor/js/beautify-html',
        'simple-uploader':'addons/simditor/js/uploader',
        'simditor':'addons/simditor/js/simditor',
        'simditor-html':'addons/simditor/js/simditor-html',
        'simditor-fullscreen':'addons/simditor/js/simditor-fullscreen',
    },
    shim: {
        'simditor': ['css!addons/simditor/css/simditor.css','simple-module','simple-hotkeys','dompurify','simple-uploader'],
        'simditor-html': ['simditor','beautify','beautify-css','html_beautify'],
        'simditor-fullscreen': ['simditor'],
    }
})
require(['jquery'], function ($) {
    if ($('.editor', document).length>0) {
        require(['simditor','simditor-html','simditor-fullscreen'], function (Simditor) {
            $('.editor', document).each(function (id, vo) {
                var editor = new Simditor({
                    textarea: $(this),
                    toolbar: ['html','|','bold', 'italic', 'underline', 'strikethrough', '|', 'ol', 'ul', 'blockquote', 'code', '|', 'link', 'image', '|', 'indent', 'outdent','|','fullscreen'],
                    defaultImage: '/static/addons/simditor/img/image.png',
                    upload: {
                        url: Config.upload_url
                    }
                });

                editor.uploader.on('beforeupload', function (e, file) {
                    var formData = new FormData();
                    formData.append("files[]",file.obj);
                    $.ajax({
                        url:file.url,
                        type:'post',
                        data: formData,
                        contentType: false,
                        processData: false,
                        success:function(res){
                            if (res.code==200) {
                                editor.uploader.trigger("uploadsuccess", [file, {success: true, file_path: res.data[0].path}]);
                            } else {
                                layer.msg("上传失败");
                            }
                        }
                    })
                    return false;
                });
            });
        })
    }
})